#include <boost/test/unit_test.hpp>
#include "ServerSocket.hpp"

class ReceiveData : public ThreadJob
{
	ServerSocket ss;
	SOCKET s;
	virtual void * DoWork()
	{
		char * buf;

		while(1)
		{
			buf = ss.ReceiveData(s);
			if(buf == 0)
				break;
			if(strlen(buf) > 0 && (char)buf != '\n')
				printf("%s", buf);
		}
		return 0;
	}

public:
	void setSS(ServerSocket & s)
	{
		ss = s;
	}

	void setSock(SOCKET &sock)
	{
		s = sock;
	}
};

/*
Test in comment because it block for socket connection

The code from the ServerSocket could have been put in here
and create thread from the code in here trought the ThreadJob 
instead of doing another layer over ServerSocket object.
*/

/*
BOOST_AUTO_TEST_CASE(server_socket_simple)
{
	Thread wait;
	Thread rcv;
	WaitForConnection w;
	
	ServerSocket ss;

	ReceiveData * r = new ReceiveData();
	r->setSS(ss);
	SOCKET s = ss.WaitForConnection(6565,2,NULL);
		
	r->setSock(s);
	rcv.Start(r);	
}*/